import torch
from tqdm import tqdm
from torch_geometric.data import Data, InMemoryDataset
import pandas as pd
from sklearn.preprocessing import LabelEncoder


def make_alarms_dataframe():
    df = pd.read_csv("data/alarms.csv")
    all_columns = ["id", "create_time", "update_time", "alarm_id", "sn", "hostname", "ip", "depart", "content",
                   "alarm_time", "send_time", "upgrade_time", "ack", "notifier", "status", "alarm_level_id",
                   "notify_status", "upgrade_status", "recovery_notify_time", "recovery_time", "upgrade_notifier",
                   "item", "agg_id", "related_agg_id", "product_labels", "product_name", "ack_message", "ack_user",
                   "mail_contacts", "phone_contacts", "upgrade_contacts", "wechat_contacts", "upgrade2_status",
                   "upgrade2_time", "upgrade2_contacts", "alarm_source_id", "alarm_type", "idc_name", "maintain_state",
                   "phone_send_time", "phone_status", "wechat_send_time", "wechat_status"]
    df.columns = all_columns
    # df.columns = ["id", "ip", "content", "product_labels"]
    use_columns = ["ip", "content", "idc_name", "product_labels"]
    not_use_columns = list(set(all_columns).difference(set(use_columns)))
    # print(not_use_columns)

    # 删除列 'C' 和 'D'，只留下列 'A' 和 'B'
    df = df.drop(not_use_columns, axis=1)
    # df = df.dropna(axis=1, na='无')
    df = df[df['product_labels'] != '无']
    df = df[df['ip'] != 'LIVE']
    df = df.dropna(axis=0,subset=['product_labels'])
    # 打印处理后的数据框
    df = df.drop_duplicates()
    # 将行索引重新排序为连续的整数索引
    df = df.reset_index(drop=True)
    return df

alarms_df = make_alarms_dataframe()
# print(alarms_df)
# # 获取行数
# num_rows = alarms_df.shape[0]
# print(num_rows)


